﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElectronicsMarket.Models;
using ElectronicsMarket.EMServices;
using ElectronicsMarket.InternalService;

namespace ElectronicsMarket.Controllers
{
    public class HomeController : Controller
    {                                                                               
        private ServicesReleaseSoapClient serviceRelease;

        public HomeController()
        {
            serviceRelease = new ServicesReleaseSoapClient();   
        }

        public ActionResult Index()
        {
            return View();
        }

        public PartialViewResult CategoryList()
        {
            return PartialView(serviceRelease.getAllCategory().ToList());
        }

        public PartialViewResult ProductList()
        {
            ProductList productList = new ProductList();
            List<Product> prodList = new List<Product>();
            List<Product> newProductList = new List<Product>();
            List<Product> topProductList = new List<Product>();

            foreach (var item in serviceRelease.getProductList().Take(8).ToList())
            {
                Product product = new Product();
                product.Prod = item;
                product.Quantity = serviceRelease.getQuantityOfProduct(item.PRODUCT_ID);
                prodList.Add(product);
            }

            foreach (var item in serviceRelease.getNewProduct().Take(4).ToList())
            {
                Product product = new Product();
                product.Prod = item;
                product.Quantity = serviceRelease.getQuantityOfProduct(item.PRODUCT_ID);
                newProductList.Add(product);
            }

            foreach (var item in serviceRelease.getTopProduct().Take(4).ToList())
            {
                Product product = new Product();
                product.Prod = item;
                product.Quantity = serviceRelease.getQuantityOfProduct(item.PRODUCT_ID);
                topProductList.Add(product);
            }

            productList.ProdList = prodList;
            productList.NewProductList = newProductList;
            productList.TopProductList = topProductList;
            return PartialView(productList);
        }
    }
}
